$(function () {
    const layer = layui.layer
    initUserInfo()


    $('#logout-btn').on('click', function() {
        layer.confirm('你确定要退出吗',{ title: '提示', icon: 3 }, index => {
            location.href ='/login.html'
            localStorage.removeItem('BIG_EVENT_TOKEN')
            layer.close(index)
        })
    })
})
function initUserInfo() {
    $.get('/my/userinfo').then(res => {
        if(res.status == 1 && res.message === '身份认证失败'){
            location.href = '/login.html'
            return layer.msg('身份认证失败')
        }
        const {username, user_pic} = res.data
        $('.username').html(username)
        if(user_pic){
            $('.layui-nav-img').show().attr('src', user_pic)
            $('.face-bg').hide()
        }else{
            $('.layui-nav-img').hide()
            $('.face-bg').show().html(username[0].toUpperCase())
        }
    })
}